import 'package:flutter/material.dart';
import 'package:share/share.dart';
import 'package:untitled/pages/room_detail/data.dart';
import 'package:untitled/widgets/common_swipper.dart';
import 'package:untitled/widgets/common_tag.dart';
import 'package:untitled/widgets/common_title.dart';
import 'package:untitled/widgets/room_appliance.dart';

import '../home/info/index.dart';

/*
 * 房屋详情页
 */
class RoomDetailPage extends StatefulWidget {
  final String roomId;

  const RoomDetailPage({Key key, this.roomId}) : super(key: key);

  @override
  State<RoomDetailPage> createState() => _RoomDetailPageState();
}
var style = TextStyle(fontSize: 18.0);
class _RoomDetailPageState extends State<RoomDetailPage> {
  RoomDetailData data;
  bool isLike = false; //是否收藏
  bool showAllTest = false;


  @override
  void initState() {
    setState(() {
      data = defaultData;
    });
    showAllTest = data.subTitle.length>100;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (null == data) return Container();

    return Scaffold(
      appBar: AppBar(
        title: Text(data.title),
        actions: [
          IconButton(
              onPressed: () {
                Share.share('http://www.baidu.com');
              },
              icon: Icon(Icons.share)),
        ],
      ),
      body: Stack(
        children: [
          ListView(
            children: [
              CommonSwiper(
                images: data.houseImgs,
              ),
              CommonTitle(data.title),
              Container(
                padding: EdgeInsets.only(left: 10.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end, //底部对齐
                  children: [
                    Text(
                      data.price.toString(),
                      style:
                          TextStyle(fontSize: 20.0, color: Colors.deepOrange),
                    ),
                    Text(
                      '元/月(押一付三)',
                      style:
                          TextStyle(fontSize: 14.0, color: Colors.deepOrange),
                    )
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10, top: 6, bottom: 6),
                child: Wrap(
                  spacing: 4.0,
                  children: data.tags.map((item) => CommonTag(item)).toList(),
                ),
              ),
              Divider(
                //下划线
                color: Colors.grey,
                indent: 10.0, //前面缩进
                endIndent: 10.0, //后面缩进
              ),
              Container(
                padding: EdgeInsets.only(left: 10, top: 6, bottom: 6),
                child: Wrap(
                  runSpacing: 20,
                  children: [
                    BaseInfoItem('面积：${data.size}平米'),

                    BaseInfoItem('楼层：${data.floor}'),
                    BaseInfoItem('房型：${data.roomType}'),
                    BaseInfoItem('装修：精装'),
                  ],
                ),
              ),
              CommonTitle('房屋配置'),
              RoomApplianceList(list: data.applicances,),
              CommonTitle('房屋概况'),
              Container(
                padding: EdgeInsets.only(left: 10.0,right: 10.0),
                child: Column(
                  children: [
                    Text(data.subTitle ?? "暂无房屋概况",
                    maxLines: showAllTest?null:5,),//通过控制最大行数来进行展开收起
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              showAllTest = !showAllTest;
                            });
                          },
                          child:Row(
                            children: [
                              Text(showAllTest?'收起':'展开'),
                              Icon(showAllTest?Icons.keyboard_arrow_up:Icons.keyboard_arrow_down)
                            ],
                          ),
                        ),

                        Text('举报')
                      ],
                    ),
                  ],
                ),
              ),
              CommonTitle('猜你喜欢'),
              Info(),
              SizedBox(height: 100,)
            ],
          ),
          Positioned(
              width: MediaQuery.of(context).size.width,
              height: 100.0,
              bottom: 0, //距离底部0px
              child: Container(
                padding:
                    EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 20),
                color: Colors.grey[200],
                child: Row(children: [
                  GestureDetector(
                    onTap: () {
                      setState(() {
                        isLike = !isLike;
                      });
                    },
                    child: Container(
                      height: 50.0,
                      width: 40.0,
                      margin: EdgeInsets.only(right: 10.0),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Icon(
                            isLike ? Icons.star : Icons.star_border,
                            size: 24.0,
                            color: Colors.green,
                          ),
                          Text(
                            isLike ? '已收藏' : '收藏',
                            style: TextStyle(fontSize: 12.0),
                          )
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                      child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      height: 50.0,
                      decoration: BoxDecoration(
                          color: Colors.cyan,
                          borderRadius: BorderRadius.circular(6)),
                      child: Center(
                        child: Text(
                          '联系房东',
                          style: TextStyle(color: Colors.white),
                        ),
                      ),
                    ),
                  )),
                  SizedBox(
                    width: 5,
                  ),
                  Expanded(
                      child: GestureDetector(
                          onTap: () {},
                          child: Container(
                            height: 50.0,
                            decoration: BoxDecoration(
                                color: Colors.green,
                                borderRadius: BorderRadius.circular(6)),
                            child: Center(
                              child: Text(
                                '联系房东',
                                style: TextStyle(color: Colors.white),
                              ),
                            ),
                          ))),
                ]),
              ))
        ],
      ),
    );
  }
}

class BaseInfoItem extends StatelessWidget {
  final String text;
  const BaseInfoItem(this.text,{Key key, }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: (MediaQuery.of(context).size.width - 30.0) / 2,
      child: Text(text,style: style),
    );
  }
}

